<template>
    <div class="list-goods">
        <div v-for="(item, index, key) in goodsList" :key="key" class="list-good-single">
            <img :src="item.pic" @click="toDetail(item)" v-lazy="item.pic" />
            <div class="good-name">{{item.name}}</div>
            <div class="good-desc">
                <div class="good-price">
                    <span>{{item.price | moneyFmt(2, '￥')}}</span>
                    <del>{{item.money | moneyFmt(2, '￥')}}</del>
                </div>
                <div class="cart-icon" @click="add(item)" v-if="item.status != 2">
                    <svg class="icon car" aria-hidden="true">
                        <use xlink:href="#icon-bianzu" />
                    </svg>
                </div>
            </div>
        </div>
        <slot></slot>
    </div>
</template>

<script>
    export default {
        name: "list-goods",
        props: {
            goodsList: {
                type: Array
            }
        },
        methods: {
            toDetail(good) {
                this.$emit("toDetail", good);
            },
            add(good) {
                this.$emit("add", good);
            }
        }
    };
</script>

<style lang='stylus' rel='stylesheet/stylus' scoped>
    @import '~@/assets/main.styl';

    .list-goods {
        display: flex;
        flex-wrap: wrap;
        flex-direction: row;
        justify-content: space-between;
        overflow: hidden;
    }

    .list-good-single {
        width: vw(185);
        background-color: grayF;
        height: vw(245);
        margin-top: titleMargin;

        img {
            width: vw(185);
            height: vw(185);
        }
    }

    .good-name {
        padding: 0 smallMargin;
        margin-top: smallMargin;
        word-vw(word12, gray3);
        line-height: vw(16);
        text-align: left;
        ellipsis();
    }

    .good-desc {
        padding: 0 smallMargin;
        display: flex;
        justify-content: space-between;

        .cart-icon {
            width: vw(24);
            height: vw(24);
            display: flex;
            justify-content: center;
            align-items: center;
            margin-top: titleMargin;

            .car {
                width: vw(18);
                height: vw(18);
                fill: gray9;
            }
        }
    }

    .good-price {
        margin-top: smallMargin;
        word-vw(word12, main-color);
        line-height: vw(16);
        text-align: left;
        overflow: hidden;

        del {
            font-size: vw(10);
            color: gray9;
            line-height: vw(14);
            margin-left: smallMargin;
        }
    }
</style>